package com.maycurobj.repository.bpm;


import com.maycurobj.entity.bpm.SaleOrderEntity;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository
public interface SaleOrderMapper extends JpaRepository<SaleOrderEntity, String> {
    /**
     * 获取符合条件的订单个数
     */
    @Query(nativeQuery = true, value= "select count(*) as counts from ije5h_saleorder where (sequenceStatus='COMPLETED' OR sequenceStatus='PROCESSING') and id in (select DISTINCT parentId from ije5h_orderlist where purchase_sure=1) and :employeeId in (select employeeNo from h_org_user b where departmentId IN (select id from h_org_department where  parentId='ff8080817af1df2c017b0a77481b025e') and `status` ='ENABLE' ) and (name like %:keyWord% or sequenceNo like %:keyWord%)")
    int getCount(@Param(value="employeeId") String employeeId,@Param(value="keyWord") String keyWord);


    /**
     * 获取符合条件的全部订单
     */
    @Query(nativeQuery = true,value = "select a.workflowInstanceId,a.sequenceNo,a.name as title,a.createdTime,a.orderTotalPrice,b.name from ije5h_saleorder a left join h_org_user b on a.creater=b.id where (a.sequenceStatus='COMPLETED' OR a.sequenceStatus='PROCESSING') and a.id in (select DISTINCT parentId from ije5h_orderlist where purchase_sure=1) and :employeeId in (select employeeNo from h_org_user b where departmentId IN (select id from h_org_department where  parentId='ff8080817af1df2c017b0a77481b025e') and `status` ='ENABLE' ) and (a.name like %:keyWord% or a.sequenceNo like %:keyWord%)")
    List<SaleOrderEntity> getData(@Param(value="employeeId") String employeeId,@Param(value="keyWord") String keyWord);
}
